﻿import QtQuick 2.11

import "."
import "_Global"
import "_Global/Button"
import "_Global/Popup"

import "_Global/Global.js" as GlobalJS
import "GameJS.js" as GameJS

Popup {
    //property string playerAccount
    signal restartGame()
    signal closeGameUI()
    signal levelChanged(bool up)


    id: root
    color: "white"

    animationType: "fade"           //出现动画类型
    duration: 500                  //动画时间
    easingType: Easing.Linear       //动画效果
    bDrag: false

    showMask: true
    maskParent: root
    maskColor: 'black'
    maskOpacity: 0.5


    function createResult() {
        var getScore;    //本局积分
        if(GameCore.isTerminateGame)
        {
            console.debug("游戏Termi退出!!!");
            getScore = GameManager.wordLib.scoreTerminate;
        }
        else
        {
            console.debug("游戏正常退出!!!");
            getScore = GameCore.wordLib.totalScore + (GameCore.isWin ? GameManager.wordLib.scoreWin : 0);
        }

        var totalScore = GameManager.userInfo.scoreCount;    //总积分
        textTotal.text = GameCore.wordLib.currentWordCount;
        textCorrect.text = GameCore.wordLib.currentCorrectCount;
        //textResult.text += "\n得分：" + (10 * GameCore.wordLib.currentCorrectCount)
        textMistake.text = GameCore.wordLib.currentMistakeCount;
        //textResult.text += "\n扣分：" + (-10 * GameCore.wordLib.currentMistakeCount)
        textScore.text = getScore;
        textFastChoice.text = GameCore.wordLib.fastChoice * GameManager.wordLib.scoreFastChoice;
        textContinualScore.text = GameCore.wordLib.continualStatistics;
        textSuccessScore.text = GameCore.isWin ? GameManager.wordLib.scoreWin : 0;
        textTotalScore.text = totalScore;


        //重新计算用户等级
        var levelInfo = UserInfo.sl_getUserLevelInfo(totalScore);

        if(levelInfo.level > Global.userInfo.userLevel) {
            //textResult.text += "\n恭喜升级";
            levelChanged(true);
            if(Global.config.bEffectOn)Global.resource.effects.effectLevelUp.play();
        }
        else if(levelInfo.level < Global.userInfo.userLevel) {
            //textResult.text += "\n很遗憾，您已降级，请再接再厉";
            levelChanged(false);
            if(Global.config.bEffectOn)Global.resource.effects.effectLevelDown.play();
        }
        Global.userInfo.userLevel = levelInfo.level;
        Global.userInfo.userLevelName = levelInfo.name;

        //console.debug("!!!等级:",levelInfo.level , Global.userInfo.userLevel)
        //console.debug(GameCore.wordLib.rightCount,GameCore.wordLib.errCount)
    }



    Image { //背景
        id: backImage
        source: Global._FixResourcePath_R("Media/Images/Game/GameOver/Back.png")
        anchors.fill: parent
    }


    /*
    ImageButton2 {  //继续
        id: buttonContinue
        source: Global._FixResourcePath_R("Media/Images/Game/GameOver/Continue.png")
        x: Global.gamePos.mapGameOver.rectContinue.x
        y: Global.gamePos.mapGameOver.rectContinue.y
        width: Global.gamePos.mapGameOver.rectContinue.width
        height: Global.gamePos.mapGameOver.rectContinue.height

        soundEffectClick: Global.resource.effects.effectButton
        bEffectOn: Global.config.bEffectOn

        onButtonClicked: {
            root.hide();
            restartGame();
        }
    }*/

    ImageButton2 {  //关闭
        id: buttonExit
        source: Global._FixResourcePath_R("Media/Images/Game/GameOver/Exit.png")
        x: Global.gamePos.mapGameOver.rectExit.x
        y: Global.gamePos.mapGameOver.rectExit.y
        width: Global.gamePos.mapGameOver.rectExit.width
        height: Global.gamePos.mapGameOver.rectExit.height

        soundEffectClick: Global.resource.effects.effectButton
        bEffectOn: Global.config.bEffectOn

        onButtonClicked: {
            root.hide();
            closeGameUI();
        }
    }



    //正确单词
    Text {
        id: textCorrect
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectTextCorrect.x
        y: Global.gamePos.mapGameOver.rectTextCorrect.y
        width: Global.gamePos.mapGameOver.rectTextCorrect.width
        height: Global.gamePos.mapGameOver.rectTextCorrect.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //错误单词
    Text {
        id: textMistake
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectTextMistake.x
        y: Global.gamePos.mapGameOver.rectTextMistake.y
        width: Global.gamePos.mapGameOver.rectTextMistake.width
        height: Global.gamePos.mapGameOver.rectTextMistake.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //总单词
    Text {
        id: textTotal
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectTextTotal.x
        y: Global.gamePos.mapGameOver.rectTextTotal.y
        width: Global.gamePos.mapGameOver.rectTextTotal.width
        height: Global.gamePos.mapGameOver.rectTextTotal.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //本局积分
    Text {
        id: textScore
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectTextScore.x
        y: Global.gamePos.mapGameOver.rectTextScore.y
        width: Global.gamePos.mapGameOver.rectTextScore.width
        height: Global.gamePos.mapGameOver.rectTextScore.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }


    //快速回答
    Text {
        id: textFastChoice
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectFastChoice.x
        y: Global.gamePos.mapGameOver.rectFastChoice.y
        width: Global.gamePos.mapGameOver.rectFastChoice.width
        height: Global.gamePos.mapGameOver.rectFastChoice.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //连击奖励
    Text {
        id: textContinualScore
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectContinualScore.x
        y: Global.gamePos.mapGameOver.rectContinualScore.y
        width: Global.gamePos.mapGameOver.rectContinualScore.width
        height: Global.gamePos.mapGameOver.rectContinualScore.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //胜利奖励
    Text {
        id: textSuccessScore
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectSuccessScore.x
        y: Global.gamePos.mapGameOver.rectSuccessScore.y
        width: Global.gamePos.mapGameOver.rectSuccessScore.width
        height: Global.gamePos.mapGameOver.rectSuccessScore.height
        font.pixelSize: Global.dpH(30)
        //font.family: ""
        color: "white"
        horizontalAlignment: Text.AlignRight
    }

    //总积分
    Text {
        id: textTotalScore
        text: qsTr("")
        x: Global.gamePos.mapGameOver.rectTextTotalScore.x
        y: Global.gamePos.mapGameOver.rectTextTotalScore.y
        width: Global.gamePos.mapGameOver.rectTextTotalScore.width
        height: Global.gamePos.mapGameOver.rectTextTotalScore.height
        font.pixelSize: Global.dpH(32)
        //font.family: ""
        color: "#A52A2A"
        horizontalAlignment: Text.AlignRight
    }



/*
    ColorButton {
        anchors.horizontalCenter: root.horizontalCenter
        anchors.verticalCenter: root.verticalCenter
        anchors.horizontalCenterOffset: -50
        anchors.verticalCenterOffset: 30
        Text {
            font.pixelSize: 24;
            id: buttonOk
            text: qsTr("继续学习")
            anchors.fill: parent
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
        onButtonClicked: {
            root.close()
            restartGame()
        }
    }



    ColorButton {
        anchors.horizontalCenter: root.horizontalCenter
        anchors.verticalCenter: root.verticalCenter
        anchors.horizontalCenterOffset: 0
        anchors.verticalCenterOffset: 30
        Text {
            font.pixelSize: 24;
            id: buttonCancel
            text: qsTr("退出学习")
            anchors.fill: parent
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
        onButtonClicked: {
            root.close()
            closeGameUI()
        }
    }
*/

    Component.onCompleted: {
    }
}
